package cn.com.ddapp.ddm.base;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.bean.mine.CityModel;
import cn.com.ddapp.ddm.bean.mine.DistrictModel;
import cn.com.ddapp.ddm.bean.mine.ProvinceModel;
import cn.com.ddapp.ddm.bean.mine.XmlParserHandler;

public class BaseAddressActivity extends BaseActivity {

    protected List<ProvinceModel> provinceList;
    protected List<CityModel> cityList;
    protected List<DistrictModel> districtList;
    /**
     * 所有省
     */
    protected List<String> mProvinceDatas = new ArrayList<String>();
    /**
     * key - 省 value - 市
     */
    protected List<String> mCitisDatas = new ArrayList<String>();
    /**
     * key - 市 values - 区
     */
    protected List<String> mDistrictDatas = new ArrayList<String>();

    /**
     * key - 区 values - 邮编
     */
    // protected Map<String, String> mZipcodeDatasMap = new HashMap<String,
    // String>();

    /**
     * 当前省的名称
     */
    protected String mCurrentProviceName;
    /**
     * 当前市的名称
     */
    protected String mCurrentCityName;
    /**
     * 当前区的名称
     */
    protected String mCurrentDistrictName = "";

    /**
     * 当前区的邮政编码
     */
    // protected String mCurrentZipCode = "";

    /**
     * 解析省市区的XML数据
     */

    protected void initProvinceDatas() {
        provinceList = null;

        try {
            InputStream input = getResources().getAssets().open("province_data.xml");
//			InputStream input = this.getClass().getClassLoader().getResourceAsStream("assets/" + "province_data.xml");
            // 创建一个解析xml的工厂对象
            SAXParserFactory spf = SAXParserFactory.newInstance();
            // 解析xml
            SAXParser parser = spf.newSAXParser();
            XmlParserHandler handler = new XmlParserHandler();
            parser.parse(input, handler);
            input.close();
            // 获取解析出来的数据
            provinceList = handler.getDataList();
            // */ 初始化默认选中的省、市、区
            if (provinceList != null && !provinceList.isEmpty()) {
                mCurrentProviceName = provinceList.get(0).getName();
                cityList = provinceList.get(0).getCityList();
                if (cityList != null && !cityList.isEmpty()) {
                    mCurrentCityName = cityList.get(0).getName();
                    List<DistrictModel> districtList = cityList.get(0)
                            .getDistrictList();
                    mCurrentDistrictName = districtList.get(0).getName();
                    // mCurrentZipCode = districtList.get(0).getZipcode();
                }
            }
            // */

            for (int i = 0; i < provinceList.size(); i++) {
                String province = provinceList.get(i).getName();
                mProvinceDatas.add(province);
                // 遍历所有省的数据
//				cityList = provinceList.get(i).getCityList();
//
//				for (int j = 0; j < cityList.size(); j++) {
//					// 遍历省下面的所有市的数据
//					String city = cityList.get(j).getName();
//					mCitisDatas.add(city);
//					districtList = cityList.get(j).getDistrictList();
//					System.out.println(city);
//					for (int k = 0; k < districtList.size(); k++) {
//						// 遍历市下面所有区/县的数据
//						String district = districtList.get(k).getName();
//						mDistrictDatas.add(district);
//						// 区/县对于的邮编，保存到mZipcodeDatasMap
//						// mZipcodeDatasMap.put(districtList.get(k).getName(),
//						// districtList.get(k).getZipcode());
//						// distrinctArray[k] = districtModel;
//						// distrinctNameArray[k] = districtModel.getName();
//					}
//				}
            }

        } catch (Throwable e) {
            e.printStackTrace();
        } finally {

        }
    }
    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public int getContentViewId() {
        return 0;
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }
}
